package com.oe.rpc.serialization;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.InputStream;
import java.io.OutputStream;

public class JsonSerializer implements RpcSerializer {

    @Override
    public byte[] serialize(Object obj) {
        return JSONObject.toJSONBytes(obj);
    }

    @Override
    public void serialize(Object obj, OutputStream out) {

    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> tClass) {
        return (T) JSONObject.parseObject(bytes,tClass);
    }

    @Override
    public <T> T deserialize(InputStream in, Class<T> tClass) {
        return null;
    }

    @Override
    public Object deserialize(InputStream in) {
        return null;
    }

    @Override
    public Object deserialize(byte[] bytes) {
        return JSON.parse(bytes);
    }
}
